﻿<!DOCTYPE html>
<!--法律法规清单管理编辑页-->
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="/static/js/common.js"></script>
    <link href="/static/js/vue-treeselect/vue-treeselect.css" rel="stylesheet" />
    <script src="/static/js/vue-treeselect/vue-treeselect.js"></script>

    <style>
        /*下载对齐*/
        .el-form-item__content {
            line-height: 28px !important;
        }
    </style>
</head>

<body>
    <div id="app" class="popupW100" v-cloak>
        <el-form :model="Form" status-icon :rules="rules" ref="form" label-width="100px" size="mini"
                 label-position="right">

            <!--第一行-->
            <el-row>
                <!--文件级别-->
                <el-col :span="11">
                    <el-col>
                        <div class="elst-select-mini">
                            <el-form-item prop="fileLeve">
                                <el-input size="mini">
                                    <template slot="prepend">
                                        {{LawRegulationsTable.FileLeve+mark.m}}
                                    </template>
                                    <!--下拉框-->
                                    <el-select @visible-change="visibleChange" v-model="Form.fileLeve" slot="suffix"
                                               :placeholder="LawRegulationsTable.FileLeve" autocomplete="off">
                                        <el-option label="请选择" value=""></el-option>
                                        <el-option v-for="item in FileLevel" :label="item.fileLeve" :value="item.id">
                                        </el-option>
                                    </el-select>
                                </el-input>
                                <span class="iputLineMust" v-if="!Form.fileLeve">
                                    <!-- 必填项添加 -->
                                    <img src="/static/images/exclamation.png" alt="">
                                </span>
                            </el-form-item>
                        </div>
                    </el-col>
                </el-col>
                <!--法律法规名称|消息验证|文本框-->
                <div v-if='show'>
                    <el-col :span="11" :offset="2">
                        <div class="elst-select-mini">
                            <el-form-item prop="lawRegulationsName">
                                <el-input v-model="Form.lawRegulationsName"
                                          :placeholder="LawRegulationsTable.LawRegulationsName" size="mini"
                                          autocomplete="off">
                                    <template slot="prepend">
                                        {{LawRegulationsTable.LawRegulationsName+mark.m}}
                                    </template>
                                </el-input>
                                <span class="iputLineMust" v-if="!Form.lawRegulationsName">
                                    <!-- 必填项添加 -->
                                    <img src="/static/images/exclamation.png" alt="">
                                </span>
                            </el-form-item>
                        </div>
                    </el-col>
                </div>
                <div v-if='!show'>
                    <el-col :span="11" :offset="2">
                        <div class="elst-select-mini">
                            <el-form-item prop="lawRegulationsName">
                                <el-input v-model="Form.lawRegulationsName"
                                          :placeholder="LawRegulationsTable.LawRegulationsName" size="mini"
                                          autocomplete="off">
                                    <template slot="prepend">
                                        {{LawRegulationsTable.LawRegulationsName+mark.m}}
                                    </template>
                                </el-input>
                                <span class="iputLineMust" v-if="!Form.lawRegulationsName">
                                    <!-- 必填项添加 -->
                                    <img src="/static/images/exclamation.png" alt="">
                                </span>
                            </el-form-item>
                        </div>
                    </el-col>
                </div>
                <!--发布主体|消息验证|文本框-->
                <el-col :span="24" style="margin-top:10px;">
                    <div class="elst-select-mini">
                        <el-form-item prop="issueSubject">
                            <el-input type="text" v-model="Form.issueSubject"
                                      :placeholder="LawRegulationsTable.IssueSubject" autocomplete="off" size="mini">
                                <template slot="prepend">
                                    {{LawRegulationsTable.IssueSubject+mark.m}}
                                </template>
                            </el-input>
                            <span class="iputLineMust" v-if="!Form.issueSubject">
                                <!-- 必填项添加 -->
                                <img src="/static/images/exclamation.png" alt="">
                            </span>
                        </el-form-item>
                    </div>
                </el-col>
            </el-row>


            <!--第四行-->
            <el-row>
                <!--文号/标准号|消息验证-->
                <el-col :span="24" style="margin-top:10px;">
                    <div class="elst-select-mini">
                        <el-form-item prop="symbol">
                            <el-input v-model="Form.symbol" :placeholder="LawRegulationsTable.Symbol" size="mini">
                                <template slot="prepend">
                                    {{LawRegulationsTable.Symbol+mark.m}}
                                </template>
                            </el-input>
                            <span class="iputLineMust" v-if="!Form.symbol">
                                <!-- 必填项添加 -->
                                <img src="/static/images/exclamation.png" alt="">
                            </span>
                        </el-form-item>
                    </div>
                </el-col>
            </el-row>
            <!--第五行-->
            <el-row>
                <el-col :span="11" style="margin-top:10px;">
                    <el-form-item prop="issueDate">
                        <div class="elst-select-mini">
                            <el-input size="mini">
                                <template slot="prepend">
                                    {{LawRegulationsTable.IssueDate+mark.m}}
                                </template>
                                <el-date-picker slot="suffix" v-model="Form.issueDate" type="date" size="mini"
                                                format="yyyy-MM-dd" value-format="yyyy-MM-dd" placeholder="选择时间">
                                </el-date-picker>
                            </el-input>
                        </div>
                        <span class="iputLineMust" v-if="!Form.issueDate">
                            <!-- 必填项添加 -->
                            <img src="/static/images/exclamation.png" alt="">
                        </span>
                    </el-form-item>

                </el-col>
                <!--实施日期|消息验证|时间选择框-->
                <el-col :span="11" :offset="2" style="margin-top:10px;">
                    <el-form-item prop="implementationDate">
                        <div class="elst-select-mini">
                            <el-input size="mini">
                                <template slot="prepend">
                                    {{LawRegulationsTable.ImplementationDate+mark.m}}
                                </template>
                                <el-date-picker slot="suffix" v-model="Form.implementationDate" type="date" size="mini"
                                                format="yyyy-MM-dd" value-format="yyyy-MM-dd" placeholder="选择时间">
                                </el-date-picker>
                            </el-input>
                        </div>
                        <span class="iputLineMust" v-if="!Form.implementationDate">
                            <!-- 必填项添加 -->
                            <img src="/static/images/exclamation.png" alt="">
                        </span>
                    </el-form-item>
                </el-col>
            </el-row>


            <!--第三行-->
            <el-row>
                <!--适用条款|多文本标记-->
                <el-col :span="24" style="margin-top:10px;">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <div class="el-input--mini el-input-group">
                                <div class="el-input-group__prepend">
                                    {{LawRegulationsTable.ApplyClause+mark.m}}
                                </div>
                                <el-input class="el-textarea__inner" type="textarea" v-model="Form.applyClause"
                                          autocomplete="off"></el-input>
                            </div>
                        </el-form-item>
                    </div>
                </el-col>

            </el-row>



            <!--第六行-->
            <el-row>
                <!--对工作情况描述-->
                <el-col :span="24" style="margin-top:10px;">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <div class="el-input--mini el-input-group">
                                <div class="el-input-group__prepend">
                                    {{LawRegulationsTable.DescribeForWork+mark.m}}
                                </div>
                                <el-input class="el-textarea__inner" type="textarea" v-model="Form.describeForWork"
                                          autocomplete="off"></el-input>
                            </div>
                        </el-form-item>
                    </div>
                </el-col>
            </el-row>
            <!--第七行-->

            <el-row>
                <!--备注-->
                <el-col :span="24" style="margin-top:10px;">
                    <div class="elst-select-mini">
                        <el-form-item prop="remarks">
                            <div class="el-input--mini el-input-group">
                                <div class="el-input-group__prepend">
                                    {{LawRegulationsTable.Remarks+mark.m}}
                                </div>
                                <el-input class="el-textarea__inner" type="textarea" v-model="Form.remarks"
                                          autocomplete="off"></el-input>
                            </div>
                        </el-form-item>
                    </div>
                </el-col>
            </el-row>
            <!--第八行-->
            <el-row>

                <!--<el-col :span="20">
            <div class="elst-select-mini">
                <el-form-item>
                    <el-input v-model="Form.Attachment" autocomplete="off" size="mini" disabled="true">
                        <template slot="prepend">
                            {{LawRegulationStandardSpecification.Attachment+mark.m}}
                        </template>
                    </el-input>
                </el-form-item>
            </div>

        </el-col>-->
                <el-col :span="24">
                    <div class="elst-select-mini">
                        <el-form-item prop="attachment">

                            <label for="Trainingtime" class="el-form-item__label"
                                   style="width: 150px;">{{LawRegulationsInput.Attachment+mark.m}}</label>

                            <span>
                                <btn-uploadfile-input v-model="Form.attachmentName" text="上传附件"
                                                      :fileid="Form.attachment" :filename="Form.attachmentName" :showdownload="true"
                                                      @success="attachmentHandle"></btn-uploadfile-input>

                            </span>
                        </el-form-item>
                    </div>

                    <!--上报部门-->
                </el-col>
                <!--<el-col :span="11" style="margin-top:10px;">
            <el-button v-if='show' class="ml10" type="success" size="mini">
                {{fujian}}
            </el-button>
        </el-col>-->
                <!--<el-col :span="4">
            <el-upload class="fl" ref="Attachmentupload" action="/api/File/UpdateFile" multiple="true"
                       :on-preview="handlePreview" :on-remove="handleRemove"
                       :before-upload="CoursewareUploadbeforeupload" :auto-upload="true" :limit="1"
                       :show-file-list="false">
                <el-button class="ml10" type="primary" size="mini" @click="btnFileListUpload">
                    {{col.lawUploadAttachment}}
                </el-button>
            </el-upload>
            <el-button v-if='show' class="ml10" type="success" size="mini">
                {{fujian}}
            </el-button>
        </el-col>-->
                <!--附件-->
                <!--<el-col :span="24" style="margin-top:10px;">
            <el-form-item :label="LawRegulationsInput.Attachment+mark.m" prop="Attachment"
                class="inputTextarea">
                <a href="#" v-model="Form.remarks">{{fujian}}</a>
            </el-form-item>
        </el-col>-->
            </el-row>
            <!--第九行|选择-->
            <el-row>
                <!--涉及部门范围文字-->
                <p>{{LawRegulationsTable.DepartmentRange+mark.m}}</p>
            </el-row>
            <!--第十行|归口部门-->
            <el-row>
                <el-col :span="24">
                    <div class="elst-select-mini vue-treeselect_style">
                        <el-form-item prop="departmentId1">
                            <el-input size="mini">
                                <template slot="prepend">
                                    {{LawRegulationsTable.BelongToClass+mark.m}}
                                </template>
                                <!--<tree-department v-model="Form.BelongToClass" :value="Form.BelongToClass"
        :multiple="true" :flat="true" :show-count="true" :disable-branch-nodes="true"
        slot="suffix" style="line-height:14px;" placeholder="请选择" />-->
                                <treeselect v-model="Form.departmentId1" :options="department" :multiple="false"
                                            :show-count="true" :disable-branch-nodes="false" slot="suffix"
                                            style="line-height: 20px;" placeholder="请选择" />
                            </el-input>
                            <span class="iputLineMust" v-if="!Form.departmentId1">
                                <!-- 必填项添加 -->
                                <img src="/static/images/exclamation.png" alt="">
                            </span>
                        </el-form-item>
                    </div>
                </el-col>
            </el-row>
            <!--第十一行|具体实施和执行部-->
            <el-row>
                <el-col :span="24">
                    <div class="elst-select-mini vue-treeselect_style">
                        <el-form-item prop="departmentId2">
                            <el-input size="mini">
                                <template slot="prepend">
                                    {{LawRegulationsTable.SpecificImplement+mark.m}}
                                </template>
                                <treeselect v-model="Form.departmentId2" :options="department" :multiple="true"
                                            :show-count="true" :disable-branch-nodes="false" slot="suffix"
                                            style="line-height: 15px;" placeholder="请选择" />
                            </el-input>
                            <span class="iputLineMust" v-if="!Form.departmentId2">
                                <!-- 必填项添加 -->
                                <img src="/static/images/exclamation.png" alt="">
                            </span>
                        </el-form-item>
                    </div>
                </el-col>
            </el-row>
            <!--第十二行|了解部门-->
            <el-row>
                <el-col :span="24">
                    <div class="elst-select-mini vue-treeselect_style">
                        <el-form-item>
                            <el-input size="mini">
                                <template slot="prepend">
                                    {{LawRegulationsTable.Understand+mark.m}}
                                </template>
                                <treeselect v-model="Form.departmentId3" :options="department" :multiple="true"
                                            :show-count="true" :disable-branch-nodes="false" slot="suffix"
                                            style="line-height: 15px;" placeholder="请选择" />
                            </el-input>
                        </el-form-item>
                    </div>
                </el-col>
            </el-row>
            <br>
            <!--第十三行|按钮-->
            <el-row type="flex" justify="end">
                <!--保存-->
                <el-button type="primary" @click="onSubmit('form')">{{col.btnSubmit}}</el-button>
                <!--提交-->
                <!--<el-button type="primary" @click="onSubmit('form')">{{col.btnSubmit}}</el-button>-->
                <el-button type="primary" @click="parent.ListItem.dialogVisible=false">{{col.btnBack}}</el-button>
            </el-row>
            <br>
            <br>
        </el-form>

    </div>
    <script>
        var uploadText = "请选择上传附件";
        Vue.component('treeselect', VueTreeselect.Treeselect)
        var app = new Vue({
            el: '#app',
            data: {
                ListItem1: {
                    //tableDate: {
                    tablebox1: [],
                    //},
                },
                department: [],
                show: '',
                //附件
                fujian: '下载',
                LBelongToClass: '',
                //表单内容
                ListItem: ListItem,
                //获取下拉菜单sex
                FileLevel: [],
                LBelongToClass: '',
                LSpecificImplement: '',
                LUnderstand: '',
                formInline: {
                    model: {
                        createFactory: null,
                     //   Attachment: ''
                    },
                    offset: 0,
                    limit: 10
                },
                Form: {
                    id: guidEmpty,
                    fileLeve: '',
                    LawRegulationsName: '',
                    IssueSubject: '',
                    ApplyClause: '',
                    Symbol: '',
                    IssueDate: '',
                    ImplementationDate: '',
                    DescribeForWork: '',
                    remarks: '',
                  //  Remarks: '',
                    BelongToClass: [],
                    SpecificImplement: [],
                    Understand: [],
                  //  Attachment: uploadText,
                    offset: 0,
                    limit: 10,
                    department: [],
                    departmentId1: null,
                    departmentId2: null,
                    departmentId3: null,
                    fL_StandardInformationDept1: [],
                    fL_StandardInformationDept2: [],
                    fL_StandardInformationDept3: [],
                    attachment: '',
                    attachmentName: '',
                    standardInformationDept:[],
                },
                //表单验证
                rules: {
                    //文件级别
                    fileLeve: [
                        verification.NotNull
                    ],
                    //法律法规名称
                    lawRegulationsName: [
                        verification.NotNull
                    ],
                    //发布主体
                    issueSubject: [
                        verification.NotNull
                    ],
                    //文号/标准号
                    symbol: [
                        verification.NotNull
                    ],
                    //颁布日期
                    issueDate: [
                        verification.NotNull
                    ],
                    //实施日期                    
                    implementationDate: [
                        verification.NotNull
                    ],
                    //归口部门                    
                    departmentId1: [
                        verification.NotNull
                    ],
                    //实施部门                    
                    departmentId2: [
                        verification.NotNull
                    ],
                    
                }
            },
            mounted: function () {
                //下拉框中数据
             //   this.FileLeve = getDicData('65');
                this.id = getUrlParam("id");
             //   this.Form.id = getUrlParam("id");
                this.GetLevelData();
                this.getData();
              
                this.getDepartmentData();
                // 以LawRegulationsName是否有数据，判断是添加还是修改，决定是否显示下载
                if (this.Form.LawRegulationsName == '') {
                    this.show = false
                } else {
                    this.show = true
                };

                if (this.id != null)
                {
                    this.Form.departmentId1 = [];
                    this.Form.departmentId2 = [];
                    this.Form.departmentId3 = [];
                    var mythis = this;
                    mythis.Form.fL_StandardInformationDept1.forEach(function (a) {
                        mythis.Form.departmentId1.push(a.departmentID);
                    });

                    mythis.Form.fL_StandardInformationDept2.forEach(function (a) {
                        mythis.Form.departmentId2.push(a.departmentID);
                    });
                    mythis.Form.fL_StandardInformationDept3.forEach(function (a) {
                        mythis.Form.departmentId3.push(a.departmentID);
                    });
                }
              
            },

            methods: {
                //解決edge下select bug
                visibleChange: function (isVisible) {
                    visibleChange(isVisible)
                },
                GetLevelData: function () {
                    var mythis = this;
                   // fileLeve: "1" 
                    myAjax("post", mythis, '/api/FL_FileLevel/GetList', { model: {}, offset: 0, limit: 10 }, function (response) {
                        console.log('response.data.pageData', response.data.pageData)
                        mythis.FileLevel = response.data.pageData
                    });
                },
              
                //初始化部门下拉树
                getDepartmentData: function () {
                    var mythis = this;
                 //获取工厂ID
                    myAjax("post", mythis, '/api/FL_StandardInformationWeb/getFactory', { model: {}, offset: 0, limit: 10 }, function (response) {
                        console.log('response.data.pageData', response.data.pageData)
                        mythis.ListItem1.tablebox1 = response.data;
                     //   alert(mythis.ListItem1.tablebox1.createFactory);


                        myAjax("post", this, '/api/SysDepartment/GetList', { model: { Name: '', Code: '', CreateFactory: mythis.ListItem1.tablebox1.createFactory }, offset: 0, limit: 10 }, function (response) {
                            mythis.department = menuHelperX(response.data.pageData, guidEmpty)
                        }, false);
                    });
                },
                handleRemove: function (file) {
                    console.log(file);
                },
                handlePreview: function (file) {
                    console.log(file.name);
                    window.open(file.url)
                },
                //上传附件文件的校验
                CoursewareUploadbeforeupload: function (file) {
                    var testmsg = file.name.substring(file.name.lastIndexOf('.') + 1)
                    //将附件名赋值到label上
                    this.Form.Attachment = file.name;
                    const extension = testmsg === 'excel'
                    const isLt10M = file.size / 1024 / 1024 < 10
               
                    //if (!extension) {
                    //    this.$message({
                    //        message: '上传文件只能是excel格式!',
                    //        type: 'warning'
                    //    });
                    //}
                    if (!isLt10M) {
                        this.$message({
                            message: '上传文件大小不能超过 10MB!',
                            type: 'warning'
                        });
                    }
                    if (extension || extension2 && isLt10M)
                        submitUpload(this, 'upload')
                    return extension || extension2 && isLt10M
                },
                btnFileListUpload: function () {
                    //若更换文件则将文件名字更换触发条件--先删除上一个文件,后添加一个文件
                    if (this.fileAttachmentUpload != uploadText) {
                        this.$refs.Attachmentupload.clearFiles();
                        this.fileAttachmentUpload = file.name;
                    }
                    else {

                    }
                    this.$refs.Attachmentupload.submit();
                },
                //归口部门选择按钮
                btn_belongClassChoose: function () { },
                //具体实施和执行按钮
                btn_specificImplement: function () { },
                //了解部门按钮
                btn_understand: function () { },
                //保存按钮
                btn_saveOk: function (formName) {
                    var mythis = this;
                    this.$refs[formName].validate(function (valid) {
                        //验证通过
                        if (valid) {
                            myAjax("post", this, '/api/LawRegulationListAdministrationInput/saveOk', null,
                                function (response) {
                                    console.log(response);
                                    if (response.result == "Success") {
                                        showMessage(response.message, 'success');
                                    }
                                    else {
                                        showMessage(response.message, 'fail');
                                    }

                                });
                        } else {
                            showMessage(msg.NoMust, 'error');
                        }
                        //验证失败
                        return false;
                    });
                },
                //提交按钮
                onSubmit: function (formName) {
                    var mythis = this;
                    this.$refs[formName].validate(function (valid) {
                        //验证通过
                        if (valid) {
                            if (mythis.Form.departmentId1) {
                                mythis.Form.fL_StandardInformationDept1 = [];
                                mythis.Form.fL_StandardInformationDept1.push({
                                    Class: String(mythis.Form.departmentId1),
                                    DeptType:"1"
                                })
                            }

                            if (mythis.Form.departmentId2) {
                                mythis.Form.fL_StandardInformationDept2 = [];
                                mythis.Form.departmentId2.forEach(function (v) {
                                    mythis.Form.fL_StandardInformationDept2.push({
                                        Class: v,
                                        DeptType: "2"
                                    })
                                })
                            }
                            if (mythis.Form.departmentId3) {
                                mythis.Form.fL_StandardInformationDept3 = [];
                                mythis.Form.departmentId3.forEach(function (v) {
                                    mythis.Form.fL_StandardInformationDept3.push({
                                        Class: v,
                                        DeptType: "3"
                                    })
                                })
                            }


                            onSubmitForm(this, '/api/FL_StandardInformationWeb/SaveHistory', mythis.Form);
                        }
                        else {
                            showMessage(msg.NoMust, 'error');
                            return false;
                        }
                    });
                },
            
                //通过ID继续赋值
                getData: function () {
                    getData(this, '/api/FL_StandardInformationWeb/get?id=' + this.id);
                },
                //归口部门input
                input: function (value) {
                    this.Form.BelongToClass = value;
                },
                //归口部门input
                input2: function (value) {
                    this.Form.SpecificImplement = value;
                },
                //归口部门input
                input3: function (value) {
                    this.Form.Understand = value;
                },
                attachmentHandle: function (response, fileid, fileName) {

                    console.log('fileid', fileid)
                    console.log('fileName', fileName)

                    this.Form.attachment = fileid;
                    this.Form.attachmentName = fileName;

                    console.log(' this.Form.attachment', this.Form.attachment)
                    console.log(' this.Form.attachmentName', this.Form.attachmentName)

                },
             
            },
        });
        //下拉树数据格式化
        function menuHelperX(list, pid) {
            var result = [];
            if (list.length <= 0)
                return list;
            list.forEach(function (v, i) {
                var temp = {};
                for (var key in v) {
                    temp[key] = v[key];
                }
                temp.label = v.name;
                temp.parentId = temp.parentId ? temp.parentId : guidEmpty;
                var obj;
                if (temp.parentId == pid) {
                    obj = temp;
                    var nextObj = menuHelperX(list, temp.id);
                    if (nextObj.length > 0) {
                        obj.children = nextObj;
                    }
                }
                if (obj)
                    result.push(obj)
            })
            return result;
        }
    </script>
</body>

</html>